package com.gutsyzhan.edoctor.controller;

import com.gutsyzhan.edoctor.assistant.EDoctorAssistant;
import com.gutsyzhan.edoctor.assistant.StreamEDoctorAssistant;
import com.gutsyzhan.edoctor.dto.ChatFormDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@Tag(name = "元元")
@RestController
@RequestMapping("/eDoctor")
public class EDoctorController {
    @Autowired
    private EDoctorAssistant eDoctorAssistant;

    @Autowired
    private StreamEDoctorAssistant streamEDoctorAssistant;

    @Operation(summary = "对话")
    @PostMapping("/chat")
    public String chat(@RequestBody ChatFormDTO chatFormDTO) {
        return eDoctorAssistant.chat(chatFormDTO.getMemoryId(), chatFormDTO.getMessage());
    }

    @Operation(summary = "流式对话")
    @PostMapping(value = "/streamChat", produces = "text/stream;charset=utf-8")
    public Flux<String> streamChat(@RequestBody ChatFormDTO chatFormDTO) {
        return streamEDoctorAssistant.chat(chatFormDTO.getMemoryId(), chatFormDTO.getMessage());
    }
}
